<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/ConstantUtil.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%@ include file="/classes/GUID.class.jsp"%>
<%@ include file="/common/basePath.jsp"%>
<%
	//获取当前用户
	if (null == session.getAttribute(SESSION_USER)) {
		// 前往登录页
		out.print("alert('对不起您没有登录或登录状态已过期，请重新登录后操作！');");
		return;
	}

	String code = getParameter(request, "code");
	String mesgBoard = (String) session.getAttribute("mesgBoard");
	session.removeAttribute("mesgBoard");
	if (nullOrEmpty(code) || !code.equals(mesgBoard)) {
		out.println("alert(\"验证码错误！\");toRefresh();");
		return;
	}

	String messager_name = getParameter(request, "messager_name");
	String messager_sex = getParameter(request, "messager_sex");
	String messager_phone = getParameter(request, "messager_phone");
	String messager_email = getParameter(request, "messager_email");
	String messager_address = getParameter(request, "messager_address");
	String title = getParameter(request, "title");
	String content = getParameter(request, "content");
	String is_public = getParameter(request, "is_public");
	String operateTypeId = getParameter(request, "operateTypeId");
	String authDepart = getParameter(request, "authDepart");
	String appUserId = getParameter(request, "appUserId");

	if (nullOrEmpty(messager_name) || nullOrEmpty(messager_sex)
			|| nullOrEmpty(messager_phone)
			|| nullOrEmpty(messager_email)
			|| nullOrEmpty(messager_address) || nullOrEmpty(title)
			|| nullOrEmpty(content)) {
		out.println("alert(\"数据提交不完整，所以选项都是必填选项！\");");
		return;
	}
	
	if(content.getBytes().length>4000){
		out.println("alert(\"留言内容过长！请精简您的留言。\");toRefresh();");
		return;
	}
	
	String messager_ip = getIpAddr(request);
	int ip_length = messager_ip.length();
	String message_id = getGUID();
	try{
		String sql = "insert into cms_public_comment (MESSAGE_ID,TITLE,OPERATE_TIME,IS_PUBLIC,RECEIVE_DEPART,OPERATE_TYPE_ID,STATUS,CONTENT,MESSAGER_NAME,MESSAGER_SEX,MESSAGER_PHONE,MESSAGER_EMAIL,MESSAGER_ADDRESS,MESSAGER_IP,IP_ISDISPLAY,EMAIL_ISDISPLAY,IP_LENGTH,APP_USER_GUID)"+ 
			" values (?,?,sysdate,?,?,?,1,?,?,?,?,?,?,?,0,0,?,?)";
		int count = executeUpdate(sql,new Object[]{message_id,title,is_public,authDepart,operateTypeId,content,messager_name,messager_sex,messager_phone,messager_email,messager_address,messager_ip,ip_length,appUserId});
		
		if(count>0){
			String msg = "art.dialog({"+
			"    padding: 0,"+
			"    title: '系统消息',"+
			"    height: 55,"+
			"    content: '提交成功！<br/>回执单号为："+message_id+"，请牢记。',"+
			"    lock: true"+
			"});addForm.reset();";
			
			
			out.println(msg);
			//保存我的办事
			String wdbsSql = "insert into app_user_activity (user_id,type,time,status,activity_id,activity_title) values (?,'3',sysdate,'0',?,?)";
			executeUpdate(wdbsSql,new Object[]{appUserId,message_id,title});
			return;
		}else{
			out.println("alert(\"提交失败！\");");
			return;
		}
	}catch(Exception e){
		out.println("alert(\"提交失败！\");");
		return;
	}
	
	
%>